var onLoadflag = false;
var status = "";
$(document).ready(function() {
      setBaseUrl();
  	if ($("#iframe", parent.document) && $("#iframe", parent.document).length > 0) {
  		parent.loginTimeout();
  		return;
  	}
  })
function notFoundImg(){
	$("#message").text("二维码获取失败");
}
function onClickImg(){
     $("#QRCodeImg").attr("src", 'loginQrCode?'+Math.random());
     $("#message").html("已刷新");
     $('#message').css({color: "#08B100"});
     if (status != "0" && status != "1") {
        setTimeout(toLogin, 1000);
     }
}
function onLoad(){
    if (!onLoadflag) {
        toLogin();
    }
    onLoadflag = true;
}
function toLogin(){
    $.ajax({
        url : getProjectName()+"/loginStatus",
        type : 'get',
        dataType : 'json',
        success : function(data) {
            status = data.status;
            if (status == "0") {
                setTimeout(toLogin, 1000);
            } else if (status == "1") {
                $("#message").html("扫码成功<br/>请在微信上进行后续操作");
                setTimeout(toLogin, 2000);
            } else if (status == "2") {
                 $("#message").html("确认成功");
                if (data.url) {
                    window.location.href = getRootPath() + data.url;
                }
            } else if (status == "3") {
                $("#message").html("二维码过期<br/>请<a id='QRCodeFresh' title='点击刷新' style='cursor: pointer;' onclick='onClickImg()'>刷新</a>二维码重新扫描");
                $('#message').css({color: "#ff0000"});
            } else {
                $("#message").html("二维码失效或异常<br/>请<a id='QRCodeFresh' title='点击刷新' style='cursor: pointer;' onclick='onClickImg()'>刷新</a>二维码重新扫描");
                $('#message').css({color: "#ff0000"});
            }
        }
    })
}
